# 
# Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
# 
# This software is licensed under the Argot Public License 
# which may be found in the file LICENSE distributed 
# with this software.
# 
# More information about this license can be found at
# http://www.einet.com.au/License
#
# The Developer of this software is Live Media Pty Ltd,
# PO Box 4591, Melbourne 3001, Australia.  The license is subject 
# to the law of Victoria, Australia, and subject to exclusive 
# jurisdiction of the Victorian courts.
#

DEBUG=yes
#STDANSI=0


CC=gcc
AS=as
AR=ar
LD=ld
SWIG = swig
PYTHONINCLUDE = /usr/include/python2.4
PYTHONLIB = python2.4
PYTHONLIBDIR = /lib/python2.4/config

# without -fno-strict-aliasing we get some warnings which I'd like to avoid
ifdef DEBUG
  CFLAGS=-Wall -g -std=c99 -fno-inline -DDEBUG -fno-strict-aliasing 
else
  ifdef STDANSI
      CFLAGS=-Wall -ansi -O2 -pedantic -DSTDANSI -DINLINE="inline extern" -fno-strict-aliasing 
  else
	  CFLAGS=-Wall -std=c99 -O2 -DINLINE="inline extern" -fno-strict-aliasing 
  endif
endif




SRCDIR = ../c/src

ARGOTLIBDIR = ../c
ARGOTLIB = argot

INCLUDES = -I$(SRCDIR) -I$(PYTHONINCLUDE) -I/usr/local/include 

LIBS = -l$(ARGOTLIB) -l$(PYTHONLIB)
LIBDIRS = -L$(PYTHONLIBDIR) -L$(ARGOTLIBDIR)

OUTDIR = _out
BINDIR = argot
PYSRCDIR = src

SWIGFLAGS = -python -modern -O -keyword -w314 -DINLINE="" -I$(SRCDIR) -outdir $(BINDIR)

all: $(BINDIR)/__init__.py $(BINDIR)/helpers.py \
     $(BINDIR)/_monolithic.dll $(OUTDIR)/monolithic_wrapper.c
	 #$(BINDIR)/_type.dll $(OUTDIR)/type_wrapper.c \
	 #$(BINDIR)/_common.dll $(OUTDIR)/common_wrapper.c \
	 #$(BINDIR)/_dictionary.dll $(OUTDIR)/dictionary_wrapper.c \
	 #$(BINDIR)/_meta.dll $(OUTDIR)/meta_wrapper.c

clean: 
	rm -f $(OUTDIR)/*
	rm -f $(BINDIR)/*


$(BINDIR)/__init__.py: $(PYSRCDIR)/__init__.py
	cp $< $@

$(BINDIR)/helpers.py: $(PYSRCDIR)/helpers.py
	cp $< $@

$(BINDIR)/_%.dll: $(OUTDIR)/%_wrapper.o
	@echo "-------------------------------------------------"
	$(CC) -shared $< $(LIBDIRS) $(LIBS) -o $@

$(OUTDIR)/%_wrapper.o: $(OUTDIR)/%_wrapper.c
	@echo "-------------------------------------------------"
	$(CC) $(CFLAGS) $(INCLUDES) -fpic -c $< -o $@
	
$(OUTDIR)/%_wrapper.c: $(PYSRCDIR)/%.i
	@echo "-------------------------------------------------"
	$(SWIG) $(SWIGFLAGS) -o $@ $<

#.SECONDARY: $(OUTDIR)/%_wrapper.c